(function() {
  var ctrls = angular.module(MyAppConfig.controllers);
  ctrls.controller('UserManageUpdateCtrl', ['$scope', '$log', 'DialogService', 'DataService', UserManageUpdateCtrl]);

  function UserManageUpdateCtrl($scope, $log, DialogService, DataService) {
    $log.debug('UserManageUpdateCtrl init...');

    // 处理scope销毁
    $scope.$on('$destroy', function() {
      $log.debug('UserManageUpdateCtrl destroy...');
    });

    $scope.formdata = DialogService.getCustomData();

    $scope.query = function() {
      DialogService.showWait('数据查询中，请稍后...');
      DataService.send(
        '/tbadminuser/query',
        {
          tbUser: $scope.formdata
        },
        function(data) {
          DialogService.hideWait();
          if (data.success && data.datas && data.datas.list) {
            $scope.formdata = data.datas.list;
            return;
          }
          DialogService.showAlert('查询失败', function() {
            DialogService.hideCustom();
          });
        });
    };

    //$scope.query();

    $scope.close = function() {
      DialogService.hideCustom();
    };

    $scope.save = function() {
      DialogService.showWait('数据保存中，请稍后...');
      DataService.send(
        '/tbadminuser/adminupdate',
        {
          tbUser: $scope.formdata
        },
        function(data) {
          DialogService.hideWait();
          DialogService.showAlert(data.message, function() {
            if (data.success) {
              DialogService.hideCustom();
            }
          });
        });
    };
  }
})();
